<!DOCTYPE html>
<html>
<head>
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="../css/login.css">
</head>
<body>
	<div id="logo">
		<img src="../img/tamp.png">
	</div>
	<div id="head" align="center">
		<div id="head-text">
			<strong>用户登录</strong><br>
			<span>用户登录进入系统!</span>
		</div>
		<form method="post">
			<input type="text" class="t1" name="username" id="username" placeholder="用户名*"><br>
			<input type="password" class="t1" name="password" id="password" placeholder="密码*"><br>
			<div id="login">
				<input type="submit" class="t3" name="" value="登录" onclick="return submit_form()">
			</div>
		</form>
		<div id="aa">
			<a href="#" class="a1">忘记密码？</a>
			<span>|</span>
			<a href="register.php" class="a2">立即注册</a>
		</div>
	</div>
    <script type="text/javascript">
        function submit_form() {
            let name = document.getElementById("username").value;
            let pwd = document.getElementById("password").value;
            if(name == '' || pwd == ''){
                alert("账号或密码未输入！");
                return false;
            }
        }
    </script>
</body>
</html>

<?php
/*include_once 'sql.php';//执行时连接*/
include 'mysql.php';//一直连接
if(!empty($_POST)){
    $mysql = new mysql();
    $name = $_POST['username'];
    $pwd = $_POST['password'];
    $sql = 'select * from test_table where username ="'.$name.'"';
    $sql_q = $mysql->select_one($sql);
    if(!empty($sql_q)){
        if($sql_q['password'] == $pwd){
            //session传值
            $_SESSION = $sql_q;
            if($sql_q['dd'] == 0){
                header('Refresh: 0; url=home.php');
                return 0;
            }elseif($sql_q['dd'] == 9){
                header('Refresh: 0; url=admin.php');
                return 0;
            }else{
                echo '<script type="text/javascript">alert("此账号已被冻结！");</script>';
            }
        }else{
            echo '<script type="text/javascript">alert("账号或密码错误！");</script>';
        }
    }else{
        echo '<script type="text/javascript">
                var mymessage=confirm("此用户名不存在！立即注册？");
                if(mymessage == true){
                     window.location.href="register.php";
                }
                </script>';
    }
    /*$select_sql = 'select username from test_table where username ="'.$name.'" and password ="'.$pwd.'"';
    $sql_q = onedata($select_sql);
    if(!empty($sql_q)){
        $_SESSION["name"] = $name;
        header('Refresh: 0; url=index.php');
        return 0;
    }else{
        echo '<script type="text/javascript">alert("账号或密码错误！");</script>';
    }*/
}
?>

